#include <iostream>
using namespace std;

char kuohao[10000];

bool judge()
{
	char ch;
	int count = 0;
	while ((ch = getchar()) != '\n')
	{
		switch (ch)
		{
		case ']':
			if (count - 1 >= 0 && kuohao[count - 1] == '[')
			{
				count -= 1;
			}
			else
			{
				return 0;
			}
			break;
		case ')':
			if (count - 1 >= 0 && kuohao[count - 1] == '(')
			{
				count -= 1;
			}
			else
			{
				return 0;
			}
			break;
		case '[':
			kuohao[count++] = ch;
			break;
		case '(':
			kuohao[count++] = ch;
			break;
		default:
			return 0;
		}
	}
	if (count != 0)
		return 0;
	return 1;
}

int main()
{
	int t;
	cin >> t;
	fflush(stdin);
	while (t--)
	{
		if (judge())
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
		fflush(stdin);
	}
	getchar();
}

